package com.example.mid;


import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {
    public static final String EXTRA_MESSAGE_ID = "com.xl.android's.MESSAGE_ID";
    public static final String EXTRA_MESSAGE_NAME = "com.xl.android's.MESSAGE_NAME";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //找到事件源
        Button btn = findViewById(R.id.btn_login);
        //设置事件监听,采用匿名内部类实现监听处理
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sendMessage(view);
            }
        });
    }
    public void sendMessage(View v){
        Log.i("MyDebug","响应按钮点击时间");
        //构建意图，从MainActivity->DisplayMessageActivity
        Intent intent = new Intent(this,DisplayActivity.class);
        //获取文本框中的数据
        EditText pt_id = findViewById(R.id.pt_id);
        EditText pt_name = findViewById(R.id.pt_name);
        String msg_id = pt_id.getText().toString();
        String msg_name = pt_name.getText().toString();
        System.out.println(msg_id+","+msg_name);
        //String message=pt_id.getText().toString();
        //把数据附加到intent上
        intent.putExtra(this.EXTRA_MESSAGE_ID,msg_id);
        intent.putExtra(this.EXTRA_MESSAGE_NAME,msg_name);
        //执行意图
        startActivity(intent);

    }
}
